﻿using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace shenhao.web.Models
{
    public class MyDbContext : DbContext
    {

        public MyDbContext(DbContextOptions options) : base(options)
        {

        }


        public DbSet<Tempertaure> Tempertaure { get; set; }








        public static MyDbContext CreateInstance(string conStr = null)
        {
            if (string.IsNullOrWhiteSpace(conStr))
            {
                conStr = "server=140.143.29.114;userid=mty;pwd=123;port=3306;database=shenhao;";
            }
            var optionBuilder = new DbContextOptionsBuilder<MyDbContext>();
            optionBuilder.UseMySQL(conStr);
            var context = new MyDbContext(optionBuilder.Options);
            context.Database.EnsureCreated();//针对当前访问的上下文对象，如果数据库中存在该表，则不做修改；否则的话进行创建
            return context;
        }







        /// <summary>
        /// 初始化数据
        /// </summary>
        public static void DbInit()
        {
           

        }


    }
}
